<template>
  <div>
    <el-input
      placeholder="请输入有关课程名得关键字"
      v-model="clName"
      :disabled="false" style="width: 250px;float: left">
    </el-input>
    <el-button type="success" size="small" style="float: left;margin-left: 20px" @click="selectBycName">点击搜索</el-button>
  <el-table
    :data="classesList"
    stripe
    style="width: 100%">
    <el-table-column
      prop="clName"
      label="视频名称"
      width="140">
    </el-table-column>
    <el-table-column
      prop="clTime"
      label="视频时长(分)"
      width="120">
    </el-table-column>
    <el-table-column
      prop="clInfo"
      label="简介"
      width="300">
    </el-table-column>
    <el-table-column
      prop="clUrl"
      label="视频地址">
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="updateClasses(scope.row)">视频编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="passOut(scope.row.clId)">视频下架</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage1"
      :page-size="pageSize"
      layout="total, prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        clName:'',
        classesList: [{

        }],
        currentPage1: 1,
        pageSize:5,
        total:100
      }
    },
    mounted() {
      this.findPage()
    },
    methods:{
      findPage(){
        this.$axios.get("http://127.0.0.1:8999/classes/findPage?pageNo="+this.currentPage1+"&pageSize="+this.pageSize+"&clName="+this.clName).then(res=>{
          if(res.data.code==200){
            this.total=res.data.data.total;
            this.classesList=res.data.data.records
            console.log(this.classesList)
          }});
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.findPage()
      },
      selectBycName(){
        this.findPage()
      },
      passOut(clId){
        this.$confirm('确定要下架该视频吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(res=>{
          this.$axios.post("http://127.0.0.1:8999/classes/passOut?clId="+clId).then(res=>{
            if(res.data.code==200){
              this.$message.success('视屏下架成功')
              this.findPage()
            }else{
              this.$message.error('课程下架失败')
            }
          })
        })
      },
      updateClasses(classes){
        console.log(classes);
        this.$router.push({name:"addVideo",params:{classes:classes}})
      }

    }
  }
</script>
